package interactive.states
{
	import events.GestureEvent;
	
	import flash.events.TimerEvent;
	import flash.geom.Point;
	
	import global.Managers;
	
	import interactive.GestureManager;
	
	import utils.EnterFrameTimer;

	/**
	 *
	 * 等待双击状态，等待单击状态的延续
	 * 1. 在最大离开延迟前没有触摸屏幕则触发双击事件并变为离开状态
	 * 2. 在最大离开延迟前触摸了屏幕则退回单击触摸状态
	 *  
	 * @author Raykid
	 * 
	 */
	public class WaitDoubleClickState implements IGestureState
	{
		private var _lastPoint					: Point;
		private var _timerLeave					: EnterFrameTimer;
		
		public function WaitDoubleClickState()
		{
			_lastPoint = new Point();
			
			_timerLeave = new EnterFrameTimer(GestureManager.CLICK_LEAVE_DELAY, 1);
			_timerLeave.addEventListener(TimerEvent.TIMER_COMPLETE, timerLeaveHandler);
		}
		private function timerLeaveHandler(event:TimerEvent):void {
			// 1. 在最大离开延迟前没有触摸屏幕则触发双击事件并变为离开状态
			var manager:GestureManager = Managers.gestureManager;
			manager.downDispatcher.dispatchEvent(new GestureEvent(GestureEvent.DOUBLE_CLICK, manager.downTarget, true, false, _lastPoint.x, _lastPoint.y));
			manager.switchState(manager.leaveState, _lastPoint);
		}

		public function backIn(manager:GestureManager, point:Point):void {
			// 无操作
		}
		public function switchIn(manager:GestureManager, point:Point):void
		{
			_lastPoint.x = point.x;
			_lastPoint.y = point.y;
			_timerLeave.start();
		}
		public function switchOut(manager:GestureManager, point:Point):void
		{
			_timerLeave.reset();
		}
		public function touch(manager:GestureManager, point:Point):void
		{
			// 2. 在最大离开延迟前触摸了屏幕则退回单击触摸状态
			manager.backToState(manager.clickTouchState, _lastPoint);
		}
		public function leave(manager:GestureManager, point:Point):void
		{
			// 无操作
		}
		public function move(manager:GestureManager, point:Point):void {
			// 无操作
		}
		public function toString():String {
			return "WaitDoubleClickState";
		}
	}
}